package com.t2t.top.beanfactory2;

import com.t2t.top.beanfactory.People;
import com.t2t.top.beanfactory.Phone;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

public class HumanFactoryBean implements FactoryBean<People>, InitializingBean {

    private String phoneInfo;

    public String getPhoneInfo() {
        return phoneInfo;
    }

    public void setPhoneInfo(String phoneInfo) {
        this.phoneInfo = phoneInfo;
    }

    @Override
    public People getObject() throws Exception {
        People people = new People();
        Phone phone = new Phone();
        String info[] = phoneInfo.split(",");
        phone.setSize(info[0]);
        phone.setName(info[1]);
        phone.setLogo(info[2]);
        people.setName(info[3]);
        people.setPhone(phone);
        return people;
    }

    @Override
    public Class<?> getObjectType() {
        return Phone.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet...");
    }
}